package com.yt.sys.server.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yt.sys.models.entity.SysPermission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SysPermissionMapper extends BaseMapper<SysPermission> {

    /**
     * 根据权限名称查找权限
     * @param permName 权限名称
     * @return 权限信息
     */
    @Select("SELECT * FROM sys_permission WHERE perm_name = #{permName} AND is_delete = 0 LIMIT 1")
    SysPermission selectByPermName(@Param("permName") String permName);

    /**
     * 根据URL查找权限
     * @param permUrl 权限URL
     * @return 权限信息
     */
    @Select("SELECT * FROM sys_permission WHERE perm_url = #{permUrl} AND is_delete = 0 LIMIT 1")
    SysPermission selectByPermUrl(@Param("permUrl") String permUrl);

    /**
     * 获取所有未删除的权限
     * @return 权限列表
     */
    @Select("SELECT * FROM sys_permission WHERE is_delete = 0 ORDER BY create_time DESC")
    List<SysPermission> selectAllActive();
}